package com.ymatou.iapi.usersafe.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.usersafe.parameter.*;
import com.ymatou.iapi.usersafe.service.*;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.utils.TestDataManager;
/**
*设置安全问题
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetSecurityQuestion{
	private static SetSecurityQuestionBean setsecurityquestionBean;
	private static SetSecurityQuestionCall setsecurityquestionCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置安全问题");
	}

	@Before
	public void caseUp() {
		setsecurityquestionBean=new SetSecurityQuestionBean();
		setsecurityquestionCall=new SetSecurityQuestionCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setsecurityquestionCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSecurityQuestion_001() {
		Logger.start(true,"设置安全问题成功");
		try {
			setsecurityquestionBean.setUserId(2);
			List<SecurityQuestionAnswer> securityQuestionAnswerList=initSecurityQuestionAnswer();
			
			setsecurityquestionBean.setSecurityQuestionAnswerList(securityQuestionAnswerList);
			setsecurityquestionCall.setData(setsecurityquestionBean);
			setsecurityquestionCall.callService();			
			Logger.verifyIsContains("success", setsecurityquestionCall.getString("LastErrorMessage"), "验证LastErrorMessage");
			Logger.verifyIsContains("200", setsecurityquestionCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyIsContains("true", setsecurityquestionCall.getString("Success"), "验证Success");
			Logger.verifyIsContains("true", setsecurityquestionCall.getString("Result"), "验证Result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetSecurityQuestion_002() {
		Logger.start(false,"缺少参数UserId,失败");
		try {
//			setsecurityquestionBean.setUserId(2);
			List<SecurityQuestionAnswer> securityQuestionAnswerList=initSecurityQuestionAnswer();
			
			setsecurityquestionBean.setSecurityQuestionAnswerList(securityQuestionAnswerList);
			setsecurityquestionCall.setData(setsecurityquestionBean);
			setsecurityquestionCall.callService();			
			Logger.verifyIsContains("非法", setsecurityquestionCall.getString("LastErrorMessage"), "验证LastErrorMessage");
			Logger.verifyEquals("100", setsecurityquestionCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("false", setsecurityquestionCall.getString("Success"), "验证Success");
			Logger.verifyEquals("false", setsecurityquestionCall.getString("Result"), "验证Result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SetSecurityQuestion_003() {
		Logger.start(false,"缺少参数SecurityQuestionAnswerList,失败");
		try {

			setsecurityquestionBean.setUserId(2);
//			List<SecurityQuestionAnswer> securityQuestionAnswerList=initSecurityQuestionAnswer();
			
//			setsecurityquestionBean.setSecurityQuestionAnswerList(securityQuestionAnswerList);
			setsecurityquestionCall.setData(setsecurityquestionBean);
			setsecurityquestionCall.callService();			
			Logger.verifyIsContains("安全问题个数不对", setsecurityquestionCall.getString("LastErrorMessage"), "验证LastErrorMessage");
			Logger.verifyEquals("-200", setsecurityquestionCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyEquals("false", setsecurityquestionCall.getString("Success"), "验证Success");
			Logger.verifyEquals("false", setsecurityquestionCall.getString("Result"), "验证Result");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetSecurityQuestion_004() {
		Logger.start(false,"安全问题个数不对,失败");
		try {
			setsecurityquestionBean.setUserId(2);
			List<SecurityQuestionAnswer> securityQuestionAnswerList=new ArrayList<>();
			SecurityQuestionAnswer securityQuestionAnswer=new SecurityQuestionAnswer();
			securityQuestionAnswer.setQuestionId(1);
			securityQuestionAnswer.setQuestionAnswer("测试");
			securityQuestionAnswerList.add(securityQuestionAnswer);
			setsecurityquestionBean.setSecurityQuestionAnswerList(securityQuestionAnswerList);
			setsecurityquestionCall.setData(setsecurityquestionBean);
			setsecurityquestionCall.callService();			
			Logger.verifyIsContains("安全问题个数不对", setsecurityquestionCall.getString("LastErrorMessage"), "验证LastErrorMessage");
			Logger.verifyIsContains("-200", setsecurityquestionCall.getString("ErrorCode"), "验证ErrorCode");
			Logger.verifyIsContains("false", setsecurityquestionCall.getString("Success"), "验证Success");
			Logger.verifyIsContains("false", setsecurityquestionCall.getString("Result"), "验证Result");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private List<SecurityQuestionAnswer> initSecurityQuestionAnswer() {
		List<SecurityQuestionAnswer> securityQuestionAnswerList=new ArrayList<>();
		SecurityQuestionAnswer securityQuestionAnswer1=new SecurityQuestionAnswer();
		securityQuestionAnswer1.setQuestionId(1);
		securityQuestionAnswer1.setQuestionAnswer("测试1"+TestDataManager.randomStr(5));
		securityQuestionAnswerList.add(securityQuestionAnswer1);
		
		SecurityQuestionAnswer securityQuestionAnswer2=new SecurityQuestionAnswer();
		securityQuestionAnswer2.setQuestionId(2);
		securityQuestionAnswer2.setQuestionAnswer("测试2"+TestDataManager.randomStr(5));
		securityQuestionAnswerList.add(securityQuestionAnswer2);
		
		SecurityQuestionAnswer securityQuestionAnswer3=new SecurityQuestionAnswer();
		securityQuestionAnswer3.setQuestionId(3);
		securityQuestionAnswer3.setQuestionAnswer("测试3"+TestDataManager.randomStr(5));
		securityQuestionAnswerList.add(securityQuestionAnswer3);
		
		return securityQuestionAnswerList;
	}
}